home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LT_HandleInput.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  48KB  |  2,190 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <clib/keymap_protos.h>
  17. #include <pragmas/keymap_pragmas.h>
  18.  
  19. /*****************************************************************************/
  20.  
  21. #include "Assert.h"
  22.  
  23. /*****************************************************************************/
  24.  
  25. STATIC LONG
  26. CurrentWrap(ObjectNode *Node,LONG Current)
  27. {
  28.     if(Current > Node->Max)
  29.         Current = Node->Min;
  30.     else
  31.     {
  32.         if(Current < Node->Min)
  33.             Current = Node->Max;
  34.     }
  35.  
  36.     return(Current);
  37. }
  38.  
  39. STATIC BOOL
  40. CurrentInBounds(ObjectNode *Node,LONG Current)
  41. {
  42.     return((BOOL)(Node->Min <= Current && Current <= Node->Max && Current != Node->Current));
  43. }
  44.  
  45. /****** gtlayout.library/LT_HandleInput ******************************************
  46. *
  47. *   NAME
  48. *    LT_HandleInput -- Filter IntuiMessage data.
  49. *
  50. *   SYNOPSIS
  51. *    LT_HandleInput(Handle,Qualifier,Class,Code,Gadget);
  52. *                     A0      D0      A1    A2    A3
  53. *
  54. *    VOID LT_HandleInput(LayoutHandle *,ULONG,ULONG *,
  55. *                        UWORD *,struct Gadget **);
  56. *
  57. *   FUNCTION
  58. *    In order to keep track of user interface actions, such as
  59. *    keys getting pressed, sliders getting moved, etc. your
  60. *    code is to call LT_HandleInput() with data copied from the
  61. *    IntuiMessage it has just received and replied.
  62. *
  63. *   INPUTS
  64. *    Handle - Pointer to a LayoutHandle structure.
  65. *
  66. *    Qualifier - The Qualifier value copied from the
  67. *        IntuiMessage structure.
  68. *
  69. *    Class - Pointer to the ULONG variable which holds the
  70. *        value copied from the Class entry of the
  71. *        IntuiMessage structure.
  72. *
  73. *    Code - Pointer to the UWORD variable which holds the
  74. *        value copied from the Code entry of the
  75. *        IntuiMessage structure.
  76. *
  77. *    Gadget - Pointer to the Gadget value copied from the
  78. *        IAddress entry of the IntuiMessage structure.
  79. *
  80. *   RESULT
  81. *    none
  82. *
  83. *   EXAMPLE
  84. *    struct IntuiMessage *IntuiMessage;
  85. *    ULONG Qualifier,Class;
  86. *    UWORD Code;
  87. *    struct Gadget *Gadget;
  88. *
  89. *    for(;;)
  90. *    {
  91. *        WaitPort(Window->UserPort);
  92. *
  93. *        while(IntuiMessage = GT_GetIMsg(Window->UserPort))
  94. *        {
  95. *            Class = IntuiMessage->Class;
  96. *            Code = IntuiMessage->Code;
  97. *            Qualifier = IntuiMessage->Qualifier;
  98. *            Gadget = IntuiMessage->Gadget;
  99. *
  100. *            GT_ReplyIMsg(IntuiMessage);
  101. *
  102. *            LT_HandleInput(Handle,Qualifier,&Class,&Code,&Gadget);
  103. *        }
  104. *    }
  105. *
  106. *   NOTES
  107. *    For BOOPSI_KIND objects keystroke activation may lead to
  108. *    unexpected results. Your application will hear a IDCMP_GADGETUP
  109. *    event, the IntuiMessage->Code value will hold the ANSI key
  110. *    code of the key the user pressed.
  111. *
  112. *    Do not call this routine before you have actually
  113. *    replied the IntuiMessage received or weird things
  114. *    may happen. This is not a suggestion, it's a threat.
  115. *
  116. ******************************************************************************
  117. *
  118. */
  119.  
  120. VOID LIBENT
  121. LT_HandleInput(REG(a0) LayoutHandle *Handle,REG(d0) ULONG MsgQualifier,REG(a1) ULONG *MsgClass,REG(a2) UWORD *MsgCode,REG(a3) struct Gadget **MsgGadget)
  122. {
  123.     ObjectNode *Node;
  124.     BOOL Activate;
  125.  
  126.     if(!Handle)
  127.         return;
  128.  
  129.     if(Handle->Failed)
  130.     {
  131.         *MsgClass = IDCMP_CLOSEWINDOW;
  132.  
  133.         if(!Handle->NeedDelay)
  134.             Handle->NeedDelay = TRUE;
  135.         else
  136.             LTP_Delay(0,500000);    // Give the guy a break
  137.  
  138.         return;
  139.     }
  140.  
  141.     Activate = FALSE;
  142.  
  143.     switch(*MsgClass)
  144.     {
  145.         case IDCMP_CHANGEWINDOW:
  146.  
  147.             if(!(Handle->Window->Flags & WFLG_SIZEGADGET) && (Handle->Window->Flags & WFLG_HASZOOM) && !V39)
  148.             {
  149.                 #ifdef DO_BOOPSI_KIND
  150.                 {
  151.                     if(Handle->BOOPSIList)
  152.                         RefreshGList((struct Gadget *)Handle->BOOPSIList,Handle->Window,NULL,(UWORD)-1);
  153.                 }
  154.                 #endif    /* DO_BOOPSI_KIND */
  155.  
  156.                 RefreshGList(Handle->List,Handle->Window,NULL,(UWORD)-1);
  157.  
  158.                 GT_RefreshWindow(Handle->Window,NULL);
  159.  
  160.                 LTP_DrawGroup(Handle,Handle->TopGroup);
  161.             }
  162.  
  163.             break;
  164.  
  165.         case IDCMP_NEWSIZE:
  166.  
  167.                 // Did the user cancel the resize operation?
  168.  
  169.             if(Handle->SizeVerified && Handle->SizeWidth == Handle->Window->Width && Handle->SizeHeight == Handle->Window->Height)
  170.             {
  171.                 Handle->SizeVerified    = FALSE;
  172.                 Handle->SizeWidth    = 0;
  173.                 Handle->SizeHeight    = 0;
  174.  
  175.                     // Put the gadgets back in
  176.  
  177.                 AddGList(Handle->Window,Handle->List,(UWORD)-1,(UWORD)-1,NULL);
  178.             }
  179.             else
  180.             {
  181.                 struct IBox Box;
  182.  
  183.                 Handle->SizeWidth    = 0;
  184.                 Handle->SizeHeight    = 0;
  185.  
  186.                 Box.Left    = 0;
  187.                 Box.Top        = 0;
  188.                 Box.Width    = Handle->Window->Width;
  189.                 Box.Height    = Handle->Window->Height;
  190.  
  191.                 LT_LockWindow(Handle->Window);
  192.  
  193.                 if((Handle->ResizeObject != NULL) && (Handle->ResizeObject->Type == LISTVIEW_KIND))
  194.                     Handle->ResizeObject->Special.List.IgnoreListContents = TRUE;
  195.  
  196.                 LT_RebuildTags(Handle,TRUE,
  197.                     LAWN_Bounds,    &Box,
  198.                 TAG_DONE);
  199.  
  200.                 LT_UnlockWindow(Handle->Window);
  201.  
  202.                 if(Handle->Failed)
  203.                     *MsgClass = IDCMP_CLOSEWINDOW;
  204.                 else
  205.                     *MsgClass = NULL;
  206.             }
  207.  
  208.             break;
  209.  
  210.         case IDCMP_REFRESHWINDOW:
  211.  
  212.             if(Handle->AutoRefresh)
  213.             {
  214.                 LT_BeginRefresh(Handle);
  215.  
  216.                 LT_EndRefresh(Handle,TRUE);
  217.  
  218.                 *MsgClass = NULL;
  219.             }
  220.  
  221.             break;
  222.  
  223.         case IDCMP_INTUITICKS:
  224.  
  225.             if(Handle->ActiveIncrementer)
  226.             {
  227.                 if(Handle->IncrementerCountdown > 0)
  228.                     Handle->IncrementerCountdown--;
  229.  
  230.                 if(Handle->IncrementerCountdown <= 0)
  231.                 {
  232.                     if(Handle->ActiveIncrementer->Host->Flags & GFLG_SELECTED)
  233.                     {
  234.                         if(Handle->ActiveIncrementer->Type == TAPEDECK_KIND)
  235.                         {
  236.                             *MsgClass    = IDCMP_GADGETUP;
  237.                             *MsgCode    = 0;
  238.                             *MsgGadget    = Handle->ActiveIncrementer->Host;
  239.                         }
  240.                         else
  241.                         {
  242.                             ObjectNode *Parent;
  243.                             LONG Number;
  244.  
  245.                             if(Handle->IncrementerAccelerate > 0 && !(MsgQualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)))
  246.                                 Handle->IncrementerAccelerate--;
  247.  
  248.                             if(Handle->IncrementerAccelerate <= 0)
  249.                             {
  250.                                 Handle->IncrementerAccelerate = 10;
  251.  
  252.                                 Handle->IncrementerIncrement *= 2;
  253.                             }
  254.  
  255.                             *MsgClass    = IDCMP_GADGETUP;
  256.                             *MsgCode    = 0;
  257.                             *MsgGadget    = Handle->ActiveIncrementer->Special.Incrementer.Parent;
  258.  
  259.                             Parent = (*MsgGadget)->UserData;
  260.  
  261.                             if(Parent->Type == FRACTION_KIND)
  262.                             {
  263.                                 STRPTR String;
  264.  
  265.                                 String = (STRPTR)LT_GetAttributes(Handle,Parent->ID,LAPR_Object,Parent,TAG_DONE);
  266.  
  267.                                 if(CallHookPkt(Parent->Special.String.IncrementerHook,(APTR)String,Handle->ActiveIncrementer->Special.Incrementer.Amount < 0 ? (APTR)INCREMENTERMSG_DECREMENT : (APTR)INCREMENTERMSG_INCREMENT))
  268.                                 {
  269.                                     LT_SetAttributes(Handle,Parent->ID,
  270.                                         GTST_String,String,
  271.                                     TAG_DONE);
  272.                                 }
  273.                             }
  274.                             else
  275.                             {
  276.                                 if(Parent->Special.Integer.IncrementerHook)
  277.                                     Number = CallHookPkt(Parent->Special.Integer.IncrementerHook,(APTR)LT_GetAttributes(Handle,Parent->ID,LAPR_Object,Parent,TAG_DONE),Handle->ActiveIncrementer->Special.Incrementer.Amount < 0 ? (APTR)INCREMENTERMSG_DECREMENT : (APTR)INCREMENTERMSG_INCREMENT);
  278.                                 else
  279.                                     Number = ((LONG)LT_GetAttributes(Handle,Parent->ID,LAPR_Object,Parent,TAG_DONE)) + Handle->ActiveIncrementer->Special.Incrementer.Amount * Handle->IncrementerIncrement;
  280.  
  281.                                 if(Number < Parent->Min)
  282.                                     Number = Parent->Min;
  283.                                 else
  284.                                 {
  285.                                     if(Number > Parent->Max)
  286.                                         Number = Parent->Max;
  287.                                 }
  288.  
  289.                                 LT_SetAttributes(Handle,Parent->ID,
  290.                                     LAPR_Object,    Parent,
  291.                                     GTIN_Number,    Number,
  292.                                 TAG_DONE);
  293.                             }
  294.                         }
  295.                     }
  296.                     else
  297.                     {
  298.                         Handle->IncrementerIncrement    = 1;
  299.                         Handle->IncrementerAccelerate    = 10;
  300.                     }
  301.  
  302.                     if(Handle->IncrementerIncrement == 1)
  303.                         Handle->IncrementerCountdown = 2;
  304.                 }
  305.             }
  306.  
  307.             break;
  308.  
  309.         case IDCMP_RAWKEY:
  310.         {
  311.             UBYTE Buffer[10];
  312.             LONG Key;
  313.             struct InputEvent event;
  314.             BOOL KeyUp;
  315.  
  316.             if((*MsgCode & ~IECODE_UP_PREFIX) == 95 && Handle->HelpHook)
  317.             {
  318.                 if(!(*MsgCode & IECODE_UP_PREFIX))
  319.                 {
  320.                     ObjectNode *Item;
  321.                     struct HelpMsg Message;
  322.                     struct IBox Box;
  323.  
  324.                     Item = LTP_FindNode_Position(Handle->TopGroup,Handle->Window->MouseX,Handle->Window->MouseY);
  325.  
  326.                     if(Item == Handle->TopGroup)
  327.                     {
  328.                         if(Item->ID <= PHANTOM_GROUP_ID)
  329.                             Item = NULL;
  330.                     }
  331.  
  332.                     if(Item)
  333.                     {
  334.                         Message.Objec